package com.yanqu.road.server.gameplayer.module.platform;

import com.yanqu.road.entity.enums.eGamePlayerEventType;
import com.yanqu.road.entity.platform.PlatformUserBehavior;
import com.yanqu.road.entity.servercenter.ServerInfo;
import com.yanqu.road.reids.subpub.eRedisChannelType;
import com.yanqu.road.server.GameServer;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.base.GeneralModule;
import com.yanqu.road.server.manger.PlatformUserIdMgr;
import com.yanqu.road.server.manger.ServerListMgr;
import com.yanqu.road.server.manger.platform.PlatformUserBehaviorMgr;
import com.yanqu.road.utils.date.DateHelper;
import com.yanqu.road.utils.string.StringUtils;

import java.util.List;

public class PlatformUserModule extends GeneralModule {

    public PlatformUserModule(GamePlayer player) {
        super(player);
    }

    @Override
    public boolean loadData() {
        return true;
    }

    @Override
    public boolean afterLoadData() {
        return false;
    }

    @Override
    public boolean saveData() {
        return true;
    }

    @Override
    public void afterLogin() {

        ServerInfo serverInfo = ServerListMgr.getServerInfo(GameServer.getInstance().getServerId());

        if(PlatformUserIdMgr.openBehavior(1, serverInfo)){
            String uid = player.getUserInfo().getPlatformUserId();
            if(!StringUtils.isNullOrEmpty(uid)) {
                int today = Integer.valueOf(DateHelper.getPyyyyMMddDateString(System.currentTimeMillis() / 1000));
                List<PlatformUserBehavior> behaviorList = PlatformUserBehaviorMgr.getBehavior(uid, today);
                for (PlatformUserBehavior behavior : behaviorList) {
                    if(behavior.getbType() == eRedisChannelType.LunTanSignIn.getType()){
                        player.notifyListener(eGamePlayerEventType.LunTanLoginTimes.getValue(), 1);
                    }
                }
            }
        }
        if(PlatformUserIdMgr.openBehavior(3, serverInfo)){
            String uid = player.getUserInfo().getPlatformUserId();
            if(!StringUtils.isNullOrEmpty(uid)) {
                int today = 3;
                List<PlatformUserBehavior> behaviorList = PlatformUserBehaviorMgr.getBehavior(uid, today);
                for (PlatformUserBehavior behavior : behaviorList) {
                    if(behavior.getbType() == eRedisChannelType.ZfbIndex.getType()){
                        player.notifyListener(eGamePlayerEventType.ZfbIndexSetting.getValue(), 1);
                    }
                }
            }
        }

    }


}
